<?php
DrawHeader(ProgramTitle());
if($_REQUEST['student_id'])
{
	$student_RET = DBGet(DBQuery("SELECT STUDENT_ID,FIRST_NAME,LAST_NAME FROM STUDENTS WHERE STUDENT_ID='".$_REQUEST['student_id']."'"));
	if(!count($student_RET))
		BackPrompt(_('That student does not exist.'));
	$attendance_RET = DBGet(DBQuery("SELECT COUNT(*) AS COUNT FROM ATTENDANCE_PERIOD WHERE STUDENT_ID='".$_REQUEST['student_id']."'"));
	$grades_RET = DBGet(DBQuery("SELECT COUNT(*) AS COUNT FROM STUDENT_REPORT_CARD_GRADES WHERE STUDENT_ID='".$_REQUEST['student_id']."'"));

	if($grades_RET[1]['COUNT']>0 || $attendance_RET[1]['COUNT']>0)
		BackPrompt(_('You cannot delete that student since there are attendance data or grades already associated with the student.  Try un-enrolling the student instead.'));
	if(DeletePrompt(_('student: ').$student_RET[1]['FIRST_NAME'].' '.$student_RET[1]['LAST_NAME'],_('permanently delete')))
	{
		DBQuery("DELETE FROM STUDENTS WHERE STUDENT_ID='".$_REQUEST['student_id']."'");
		DBQuery("DELETE FROM STUDENT_ENROLLMENT WHERE STUDENT_ID='".$_REQUEST['student_id']."'");
		DBQuery("DELETE FROM SCHEDULE WHERE STUDENT_ID='".$_REQUEST['student_id']."'");
		// might leave orphan address records
		$message = '<IMG SRC=assets/check.gif>'._('That student has been deleted.').'<BR><BR>';
		unset($_REQUEST['student_id']);
		unset($_SESSION['REQUEST_vars']['student_id']);
		unset($_SESSION['student_id']);
		
	}
}

if(!$_REQUEST['student_id'])
{
	$message .= "<FORM action=Modules.php?modname=$_REQUEST[modname] method=POST>";
	$message .= '<font color=gray>'._('Student ID of the student you would like to delete').' </font>';
	$message .= '<input type="text" name="student_id" />';
	$message .= '<INPUT type=submit value=Delete>';
	$message .= '</FORM>';
}
echo '<BR>';
if($message)
	DrawBlock('',$message);
?>
